package com.example.rjb_shoping.controller;

import com.example.rjb_shoping.entity.RjbFavorite;
import com.example.rjb_shoping.service.RjbFavoriteService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RjbFavorite)表控制层
 *
 * @author makejava
 * @since 2021-08-07 16:24:26
 */
@RestController
@RequestMapping("rjbFavorite")
public class RjbFavoriteController {
    /**
     * 服务对象
     */
    @Resource
    private RjbFavoriteService rjbFavoriteService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public RjbFavorite selectOne(Integer id) {
        return this.rjbFavoriteService.queryById(id);
    }

    @PostMapping("insertFavorite")
    public int insertFavorite(Integer cid,Integer mid){
        RjbFavorite rjbFavorite1 = rjbFavoriteService.selectcF(cid, mid);
        if (rjbFavorite1==null){
            RjbFavorite rjbFavorite = new RjbFavorite();
            rjbFavorite.setCId(cid);
            rjbFavorite.setMId(mid);
            return this.rjbFavoriteService.insert(rjbFavorite);
        }else {
            return -1;
        }


    }
    @GetMapping("selectByCid")
    public List<RjbFavorite> selectByCid(Integer cid){
        return this.rjbFavoriteService.selectByCid(cid);
    }
    @GetMapping("deleteById")
    public boolean deleteById(Integer fid){
        return this.rjbFavoriteService.deleteById(fid);
    }
    @PostMapping("selectcF")
    public RjbFavorite selectcF(Integer cid, Integer mid){
        return this.rjbFavoriteService.selectcF(cid,mid);
    }
}
